<?php
namespace plugins\user\model;

use plugins\department\model\DepartmentModel;
use think\Db;
use think\Model;

/**
 * 人员模型
 */
class UserModel extends Model
{

    public function getDetail($item){
        if(!empty($item['avatar'])){
            $item['avatar'] = zy_domain().'/'.$item['avatar'];
        }
        if($item['last_login_time']>0){
            $item['last_login_time'] = date('Y-m-d H:i:s',$item['last_login_time']);
        }else{
            $item['last_login_time'] = '';
        }
        //部门
        $department_name = '-';
        $departmentModel = new DepartmentModel();
        $department = $departmentModel->where('id',$item['department_id'])->find();
        if(!empty($department)){
            $department_name = $department['name'];
        }
        $item['department_name'] = $department_name;

        $item['create_time'] = date('Y-m-d H:i:s',$item['create_time']);
        $item['edit_time'] = date('Y-m-d H:i:s',$item['edit_time']);
        //创建人名称
        $user_name = '-';
        $user = Db::name('user')->where('id',$item['create_uid'])->find();
        if(!empty($user)){
            $user_name = $user['user_login'];
        }
        $item['user_name'] = $user_name;
        //地区名称
        $address_name = '-';
        $address = Db::name('address')->where('cri_code',$item['address'])->find();
        if(!empty($address)){
            $address_name = $address['cri_name'];
        }
        $item['address_name'] = $address_name;

        return $item;
    }

}
